import { _decorator, Component, Node, Label } from 'cc';
import { SHARE_CHANNEL } from '../../ccc3-framework-core/const/MSG';
import dataUtil from '../../ccc3-framework-core/framework/modules/dataUtil';
import { memoryConfig } from '../../ccc3-framework-core/framework/modules/memoryConfig';
import { uiManager } from '../../ccc3-framework-core/framework/modules/uiManager';
import { UiForm } from '../../ccc3-framework-core/framework/ui/uiForm';
import { platformUtil } from '../../ccc3-framework-core/platform/platformUtil';
import { CategoryDefine } from '../CustomDefine';
import { moneyUtil } from './moneyUtil';
const { ccclass, property } = _decorator;

@ccclass('shareForm')
export class shareForm extends UiForm {

    @property(Node)
    btnShare: Node = null;

    @property(Node)
    btnClose: Node = null;

    @property(Label)
    txtCoin: Label = null;

    start() {
        console.log("shareForm start");
        this.bindTouchEnd(this.btnShare, this.onShare);
        this.bindTouchEnd(this.btnClose, this.hideForm);
    }

    private onShare() {
        console.log("shareForm onShare");
        platformUtil.currentPlatform.share(SHARE_CHANNEL.VIDEO,
            (res) => {
                if (res) {
                    uiManager.showToast(`分享成功!获得${this.share_reward_coin}体力`);
                    dataUtil.addUnlock(1, CategoryDefine.FATIGUE, 1, 0);
                    platformUtil.currentPlatform.showInter();
                    this.hideForm();
                }
            },
            (res) => {
                uiManager.showToast("分享失败")
            });
    }

    private share_reward_coin: number = 100;
    public init() {
        console.log("shareForm init");
        this.share_reward_coin = memoryConfig.instance.getIntKey("share_reward_coin", 100);
        this.txtCoin.string = `${this.share_reward_coin}`;

    }
}

